package com.yunzo.coc.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.yunzo.coc.common.bean.coc.BasicCityEntey;
import com.yunzo.coc.common.bean.param.Collect;
import com.yunzo.coc.common.utils.DateUtils;
import com.yunzo.coc.common.utils.PoiExt;
import com.yunzo.coc.common.utils.RandomUtils;
import com.yunzo.coc.common.utils.StringUtils;
import com.yunzo.coc.model.BasicAreainfoModel;
import com.yunzo.coc.model.BasicCityModel;
import com.yunzo.coc.model.BasicProvincerModel;
import com.yunzo.coc.model.BasicSmsauthcodeModel;
import com.yunzo.coc.model.GroupBusinessinfoModel;
import com.yunzo.coc.model.GroupContactsModel;
import com.yunzo.coc.model.GroupDynamicinfoModel;
import com.yunzo.coc.model.GroupInfoModel;
import com.yunzo.coc.model.GroupInforminfoModel;
import com.yunzo.coc.model.GroupMemberModel;
import com.yunzo.coc.model.GroupMemberinfoModel;
import com.yunzo.coc.model.OLDGroup;

/**
 * @author xiaobo
 * @date 2015/8/4
 * @package com.yunzo.coc.action
 */
public class IndexAction extends Controller {
    public void index () {
        render("index.jsp");
    }
    
    public void doc() {
        render("doc/index.html");
        
    }

    public void city()
    {
    	List<BasicCityEntey> list=null;
    	List<BasicCityEntey> cnlist=null;
    	List<BasicCityEntey> anlist=null;
    	List<BasicProvincerModel> plist=BasicProvincerModel.dao.find("select * from y_basic_province");
    	List<BasicCityModel>  blist=null;
    	List<BasicAreainfoModel> alist=null;
    	
    	if(plist!=null)
    	{
    		BasicCityEntey bc=null;
    		BasicCityEntey city=null;
    		BasicCityEntey area=null;
    		list=new ArrayList<BasicCityEntey>();
    		for(BasicProvincerModel pm:plist)
    		{
    			cnlist=new ArrayList<BasicCityEntey>();
    			bc=new BasicCityEntey();
    			bc.setId(pm.getStr(BasicProvincerModel.PROVINCEID));
    			bc.setName(pm.getStr(BasicProvincerModel.PROVINCE));
    			bc.setFatherid("");
    			bc.setSortnumber(pm.getNumber(BasicProvincerModel.SORTNUMBER).intValue());
    			blist=BasicCityModel.dao.find("select * from y_basic_city where father=?",pm.getStr(BasicProvincerModel.PROVINCEID));
    			for(BasicCityModel cm:blist)
    			{
    				anlist=new ArrayList<BasicCityEntey>();
    				city=new BasicCityEntey();
    				city.setId(cm.getStr(BasicCityModel.CITYID));
    				city.setName(cm.getStr(BasicCityModel.CITY));
    				city.setFatherid(cm.getStr(BasicCityModel.FATHER));
    				city.setSortnumber(cm.getNumber(BasicCityModel.SORTNUMBER).intValue());
    				alist=BasicAreainfoModel.dao.find("select * from y_basic_area where father=?",cm.getStr(BasicCityModel.CITYID));
    				for(BasicAreainfoModel am:alist)
    				{
    					area=new BasicCityEntey();
    					area.setId(am.getStr(BasicAreainfoModel.AREAID));
    					area.setName(am.getStr(BasicAreainfoModel.AREA));
    					area.setFatherid(am.getStr(BasicAreainfoModel.FATHER));
    					area.setSortnumber(am.getNumber(BasicAreainfoModel.SORTNUMBER).intValue());
    					
    					anlist.add(area);
    				}
    				city.setChildren(anlist);
    				cnlist.add(city);
    			}
    			bc.setChildren(cnlist);
    			list.add(bc);
    		}
    	}
    	
    	renderJson(list);
    }
    public void group()
    {
    	Map<String,String> key=new HashMap<String, String>();
    	key.put("4028800046ccc0e40146ccc0e4580000", "深圳云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccaa9380001", "北京云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccaf9ca0002", "上海云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccb4d570003", "广州云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccbbbcd0004", "成都云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccc05f00005", "重庆云筑科技有限公司");
    	key.put("4028800046ccc67a0146cccc507f0006", "东莞云筑科技有限公司");
    	key.put("8a21693446ea9a3c0146efbce1411cc6", "南昌云筑科技有限公司");
    	key.put("8a2169344747d53e01475853aee5412f", "长沙云筑科技有限公司");
    	
    	Map<String,String> typekey=new HashMap<String, String>();
    	typekey.put("101", "商会");
    	typekey.put("102", "俱乐部");
    	typekey.put("103", "名族党派");
    	typekey.put("104", "协会 ");
    	typekey.put("105", "服务中心");
    	typekey.put("106", "天使投资人公司");
    	typekey.put("107", "狮子会");
    	typekey.put("108", "同乡会");
    	typekey.put("109", "校友会");
    	typekey.put("110", "论坛");
    	typekey.put("111", "促进会");
    	
    	String temp="";
    	List<OLDGroup> olist=OLDGroup.dao.find("SELECT * from y_basic_socialgroups where FBillState=5");
    	for(OLDGroup og :olist)
    	{
    		if(og.getStr("logo")!=null)
    		{
	    		if(og.getStr("logo").indexOf(",")!=-1)
	    		{
	    			temp=og.getStr("logo").substring(0,og.getStr("logo").length()-1);
	    		}else
	    			temp=og.getStr("logo");
    		}else
    			temp=null;
    		new GroupInfoModel().set(GroupInfoModel.ID, RandomUtils.randomCustomUUID())
    		.set(GroupInfoModel.VERSION,0)
    		.set(GroupInfoModel.ORDERIDS,0)
    		.set(GroupInfoModel.GNAME,og.getStr("FName"))
    		.set(GroupInfoModel.GSHORTNAME,og.getStr("FAbbreviation"))
    		.set(GroupInfoModel.GREGPEOPLE,(og.getInt("FNumberPeople")!=null ?og.getInt("FNumberPeople"):0))
    		.set(GroupInfoModel.GROUPLOGO,temp)
    		.set(GroupInfoModel.GADDRESS,og.getStr("FAddress"))
    		.set(GroupInfoModel.GINTRO,og.getStr("FComment"))
    		.set(GroupInfoModel.DEPARTNAME,key.get(og.getStr("FCompaniesID")))
    		.set(GroupInfoModel.GCNAME,og.getStr("FClientContacts"))
    		.set(GroupInfoModel.GCTELLPHONE,og.getStr("FIPhone"))
    		.set(GroupInfoModel.GCEMAIL,og.getStr("FEmail"))
    		.set(GroupInfoModel.GTYPE,typekey.get(og.getStr("FTypeID")))
    		.set(GroupInfoModel.GLEVEL,og.getStr("FLevel"))
    		.set(GroupInfoModel.CREATETIME,(og.getDate("FCreateTime")!=null?og.getDate("FCreateTime"):new Date()))
    		.set(GroupInfoModel.COMMENTS,og.getStr("FComment")).save();
    		
    	}
    }
    /**
     * 查询手机验证码 *
     * 测试使用*
     */
    public void findCode () {
        String mobile = getPara("mid");
        if (StringUtils.isNotEmpty(mobile)) {
            String codeStr = "没查到该手机对应的验证码";
            BasicSmsauthcodeModel code = BasicSmsauthcodeModel.dao.findById(mobile);
            if (code != null && StringUtils.isNotEmpty(code.getStr(BasicSmsauthcodeModel.CODE))) {
                codeStr = code.getStr(BasicSmsauthcodeModel.CODE);
            }
            renderHtml(codeStr);
        }

    }
    /**
     * 插入通讯录数据
     */
    public void insertconet()
    {
    	String filename=null,groupid=null,tcode=null;
    	groupid=getPara("groupid");
    	filename=getPara("filename");
    	tcode=getPara("tcode");
    	if(groupid!=null&&filename!=null&&tcode!=null&&tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
	      	List<Collect> listkey=new ArrayList<Collect>();
	      	Object[][] conetdata=PoiExt.ReadExcel(filename,3);
	    	System.out.println("通讯录职务数据长度："+conetdata.length);
	    	
	    	for(int i=0;i<conetdata.length;i++)
	    	{
	    		listkey.add(new Collect(conetdata[i][1].toString(), conetdata[i][2].toString()));

	    	}
	      
	    	Boolean flag=false;
	    	for(int i=0;i<listkey.size();i++)
	    	{
	    		flag=new GroupContactsModel().set(GroupContactsModel.ID,RandomUtils.randomCustomUUID())
	    		.set(GroupContactsModel.VERSION, 0)
	    		.set(GroupContactsModel.ORDERIDS,i)
	    		.set(GroupContactsModel.GROUPID,groupid)
	    		.set(GroupContactsModel.IMAAGES,"02.png")
	    		.set(GroupContactsModel.CNAMES,listkey.get(i).getPid())
	    		.set(GroupContactsModel.ISPARENT,true)
	    		.set(GroupContactsModel.MIDS,listkey.get(i).getCollectinfo())
	    		.set(GroupContactsModel.STATUS,0)
	    		.set(GroupContactsModel.CREATETIME,new Date()).save();
	    		
	    		System.out.println("第"+i+"个数据："+flag);
	    	}
	    	System.out.println("插入通讯录数据已经完成！！");
    	}else
    		return;
    }
    /**
     * 插入会员信息
     */
    public void insertMember()
    {
    	String pwd="21218cca77804d2ba1922c33e0151105";
    	String groupid=null,groupname=null,filename=null,tcode=null;
    	Object[][] memberdata=null;
    	groupid=getPara("groupid");
    	groupname=getPara("groupname");
    	filename=getPara("memberfilename");
    	tcode=getPara("tcode");
    	if(groupid==null||groupname==null||tcode==null||!tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
    		System.out.println("groupid||groupname||filename其中每一个参数都不能为空");
    		return;
    	}
    	if(filename!=null)
    		memberdata=PoiExt.ReadExcel(filename,5);
    	else
    		return;
    	
    	System.out.println("会员数据数据长度："+memberdata.length);
    	Boolean mflag=false;
    	Boolean minfoflag=false;
    	GroupMemberModel gmm=null;
    	String groupids=null;
    	if(memberdata!=null)
    	{
	    	for(int i=0;i<memberdata.length;i++)
	    	{
	    		System.out.println("数据第"+i+"个:"+memberdata[i][1]+","+memberdata[i][2]+","+memberdata[i][3]+","+memberdata[i][4]);
	    		gmm=GroupMemberModel.dao.findFirst("SELECT * FROM y_group_member WHERE mids='"+ memberdata[i][4]+"'");
	    		if(gmm!=null)
	    		{
	    			if(gmm.getStr(GroupMemberModel.GROUPIDS).indexOf(",")!=-1)
	    			{
	    				if(gmm.getStr(GroupMemberModel.GROUPIDS).indexOf("'"+groupid+"'")!=-1)
	    				{
	    					groupids=gmm.getStr(GroupMemberModel.GROUPIDS);
	    				}else
	    					groupids=gmm.getStr(GroupMemberModel.GROUPIDS)+","+groupid;
	    			}else
	    				groupids=!gmm.getStr(GroupMemberModel.GROUPIDS).equals(groupid)?(gmm.getStr(GroupMemberModel.GROUPIDS)+","+groupid):gmm.getStr(GroupMemberModel.GROUPIDS);
	    			
	    			Db.update("UPDATE  y_group_member SET groupids = '"+groupids+"'  WHERE mids='"+memberdata[i][4]+"'");
	    			continue;
	    		}else
	    		{
	    			mflag=new GroupMemberModel().set(GroupMemberModel.ID, RandomUtils.randomCustomUUID())
		    				.set(GroupMemberModel.VERSION,0)
		    				.set(GroupMemberModel.ORDERIDS,0)
		    				.set(GroupMemberModel.REALNAME,memberdata[i][1])
		    				.set(GroupMemberModel.GROUPIDS,groupid)
		    				.set(GroupMemberModel.GROUPNAMES,groupname)
		    				.set(GroupMemberModel.MID,memberdata[i][4])
		    				.set(GroupMemberModel.HEADIMAGE,memberdata[i][2])
		    				.set(GroupMemberModel.SEX,memberdata[i][3])
		    				.set(GroupMemberModel.PWD,pwd)
		    				.set(GroupMemberModel.ISSHOWME,0)
		    				.set(GroupMemberModel.ISSHOWTELLPHONE,0)
		    				.set(GroupMemberModel.STATUS,0)
		    				.set(GroupMemberModel.CREATETIME,new Date())
		    				.save();
		    		minfoflag=new GroupMemberinfoModel().set(GroupMemberinfoModel.ID, RandomUtils.randomCustomUUID())
		    				.set(GroupMemberinfoModel.VERSION,0)
		    				.set(GroupMemberinfoModel.ORDERIDS,0)
//		    				.set(GroupMemberinfoModel.REALNAME,memberdata[i][1])
		    				.set(GroupMemberinfoModel.NIKENAME,memberdata[i][1])
		    				.set(GroupMemberinfoModel.MID,memberdata[i][4])
//		    				.set(GroupMemberinfoModel.HEADIMAGE,memberdata[i][2])
//		    				.set(GroupMemberinfoModel.SEX,memberdata[i][3])
		    				.set(GroupMemberinfoModel.CREATETIME,new Date())
		    				.save();
	    		}
	    		System.out.println("会员保存:"+mflag+"\t 会员详细信息保存:"+ minfoflag);
	    	}
    	}
    	System.out.println(" <=====会员数据已经全部保存完！！！");
    }
    public void insertbaseinfo()
    {
    	String groupid=null,dynfilename=null,informfilename=null,tcode=null;
    	Object[][] dyninfo=null,informinfo=null;
    	groupid=getPara("groupid");
    	dynfilename=getPara("dynfilename");
    	informfilename=getPara("informfilename");
    	tcode=getPara("tcode");
    	if(groupid==null||dynfilename==null||informfilename==null||tcode==null||!tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
    		System.out.println("groupid||dynfilename||informfilename其中每一个参数都不能为空");
    		return;
    	}
    	if(dynfilename!=null)
    		dyninfo=PoiExt.ReadExcel(dynfilename,4);
    	
    	if(informfilename!=null)
    		informinfo=PoiExt.ReadExcel(informfilename,4);
    	
    	Boolean dynflag=false;
    	Boolean informflag=false;
    	if(dyninfo!=null)
    	{
    		System.out.println("团体动态数据长度："+dyninfo.length);
	    	for(int i=1;i<dyninfo.length;i++)
	    	{
	    		dynflag=new GroupDynamicinfoModel()
	    		.set(GroupDynamicinfoModel.ID, RandomUtils.randomCustomUUID())
	    		.set(GroupDynamicinfoModel.VERSION, 0)
	    		.set(GroupDynamicinfoModel.ORDERIDS, 0)
	    		.set(GroupDynamicinfoModel.GROUPIDS, groupid)
	    		.set(GroupDynamicinfoModel.DYTITLE,dyninfo[i][1])
	    		.set(GroupDynamicinfoModel.DYLOGO,dyninfo[i][2])
	    		.set(GroupDynamicinfoModel.DYCOMMENT,dyninfo[i][3])
	    		.set(GroupDynamicinfoModel.STATUS,0)
	    		.set(GroupDynamicinfoModel.CREATETIME,new Date())
	    		.save();
	    		
	    		System.out.println(i+"<=====动态信息保存:"+dynflag);
	    	}
	    	System.out.println("<=====动态数据已经全部保存完！！！");
    	}
    	if(informinfo!=null)
    	{
    		System.out.println("团体通知集合数据长度："+informinfo.length);
	    	for(int i=1;i<informinfo.length;i++)
	    	{
	    		informflag=new GroupInforminfoModel()
	    		.set(GroupInforminfoModel.ID, RandomUtils.randomCustomUUID())
	    		.set(GroupInforminfoModel.VERSION, 0)
	    		.set(GroupInforminfoModel.ORDERIDS, 0)
	    		.set(GroupInforminfoModel.GROUPIDS, groupid)
	    		.set(GroupInforminfoModel.INFOTITLE,informinfo[i][1])
	    		.set(GroupInforminfoModel.INFOLOGO,informinfo[i][2])
	    		.set(GroupInforminfoModel.INFOCOMMENT,informinfo[i][3])
	    		.set(GroupInforminfoModel.STATUS,0)
	    		.set(GroupInforminfoModel.INFOBEGINTIME,new Date())
	    		.set(GroupInforminfoModel.INFOENDTIME,new Date())
	    		.set(GroupInforminfoModel.CREATETIME,new Date())
	    		.save();
	    		System.out.println(i+"<=====通知信息保存:"+informflag);
	    	}
	    	System.out.println("<=====通知数据已经全部保存完！！！");
    	}
    }
    /**
     * 插入团体商机
     */
    public void insertBuesinfolist()
    {
    	String groupid=null,businfofilename=null,tcode=null;
    	Object[][] businfodata=null;
    	groupid=getPara("groupid");
    	businfofilename=getPara("businfofilename");
    	tcode=getPara("tcode");
    	if(groupid==null||businfofilename==null||tcode==null||!tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
    		return;
    	}
    	if(businfofilename!=null)
    		businfodata=PoiExt.ReadExcel(businfofilename,10);
    	System.out.println("商机列表长度："+businfodata.length);
    	boolean businfoflag=false;
    	if(businfodata!=null)
    	{
	    	for(int i=1;i<businfodata.length;i++)
	    	{
	    		businfoflag = new GroupBusinessinfoModel()
	    		.set(GroupBusinessinfoModel.ID, RandomUtils.randomCustomUUID())
	    		.set(GroupBusinessinfoModel.GROUPIDS, groupid)
	    		.set(GroupBusinessinfoModel.MID, "15184389193")
	    		.set(GroupBusinessinfoModel.BICNAME, businfodata[i][3])
	    		.set(GroupBusinessinfoModel.BICTEL, businfodata[i][4])
	    		.set(GroupBusinessinfoModel.BITRADE, businfodata[i][1])
	    		.set(GroupBusinessinfoModel.BIADDRESS,businfodata[i][2])
	    		.set(GroupBusinessinfoModel.BIVALIDITY,"长期有效")
	    		.set(GroupBusinessinfoModel.BITITLE, businfodata[i][0])
	    		.set(GroupBusinessinfoModel.BICOMMENT, businfodata[i][5])
	    		.set(GroupBusinessinfoModel.BIIAMGES, businfodata[i][7])
	    		.set(GroupBusinessinfoModel.ISOPEN, 0)
	    		.set(GroupBusinessinfoModel.CREATETIME, DateUtils.getDate())
	    		.set(GroupBusinessinfoModel.ORDERIDS, i)
	    		.set(GroupBusinessinfoModel.VERSION, 0)
	    		.save();
	    		
	    		System.out.println("插入第"+i+"条商机信息标记："+businfoflag);
	    	}
	    	System.out.println("<=====商机数据已经全部保存完！！！");
    	}
    
    }
    /**
     * 清理团体通讯录数据
     */
    public void clearGroupContentData()
    {
    	String groupid=null,tcode=null,mgroupids=null;
    	StringBuffer bumids=new StringBuffer();
    	String[] mids=null;
    	String[] groupids=null;
    	GroupMemberModel gmember=null;
    	GroupMemberinfoModel gmemberinfo=null;
    	Boolean flag=false;
    	groupid=getPara("groupid");
    	tcode=getPara("tcode");
    	if(groupid==null||tcode==null||!tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
    		return;
    	}
    	List<GroupContactsModel> listcont=GroupContactsModel.dao.find("select * from y_group_contacts where 1=1 and  groupid='"+groupid+"'  ORDER BY orderids");
    	if(listcont!=null)
    	{
    		for(GroupContactsModel gcont:listcont)
    		{
    			bumids.append(gcont.getStr(GroupContactsModel.MIDS));
    			if(gcont.getStr(GroupContactsModel.MIDS).indexOf(",")!=-1)
    			{
    				mids=gcont.getStr(GroupContactsModel.MIDS).split(",");
    				for(String mid:mids)
    				{
    					gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+mid+"'");
    					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
    					if(gmember!=null)
    					{
    					if(gmember.getStr(GroupMemberModel.GROUPIDS).indexOf(",")!=1)
    					{
    						//update one memeber to many group info
//    						groupids=gmember.getStr(GroupMemberModel.GROUPIDS).split(",");
//    						for(String gids:groupids)
//    						{
//    							if(gids.equals(groupid))
//    							{
//    								continue;
//    							}else
//    								mgroupids+=gids+",";
//    						}
//    						gmember.set(GroupMemberModel.GROUPIDS, mgroupids.substring(0, mgroupids.length()-1));
//    						gmember.update();
    						continue;
    					}else
    					{
    						flag=gmember.delete();
    						if(!flag)
    						{
    							flag=false;
    						}
    						System.out.println("<========clear Content member data Sussess!!========>flag:"+flag);
    						flag=gmemberinfo.delete();
    						if(!flag)
    						{
    							flag=false;
    							
    						}
    						System.out.println("<========clear Content member info data Sussess!!========>flag:"+flag);
    					}
    					System.out.println("<========clear Content member info data Sussess!!========>flag:"+flag+"<======>content name:"+gcont.getStr(GroupContactsModel.CNAMES));
    					}
    				}
    			}else
    			{
    				String mid=gcont.getStr(GroupContactsModel.MIDS);
    				gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+mid+"'");
					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
					if(gmember.getStr(GroupMemberModel.GROUPIDS).indexOf(",")!=1)
					{
						//update one memeber to many group info
//						groupids=gmember.getStr(GroupMemberModel.GROUPIDS).split(",");
//						for(String gids:groupids)
//						{
//							if(gids.equals(groupid))
//							{
//								continue;
//							}else
//								mgroupids+=gids+",";
//						}
//						gmember.set(GroupMemberModel.GROUPIDS, mgroupids.substring(0, mgroupids.length()-1));
//						gmember.update();
						continue;
					}else
					{
						flag=gmember.delete();
						if(!flag)
						{
							flag=false;
						}
						flag=gmemberinfo.delete();
						if(!flag)
						{
							flag=false;
							
						}
					}
    			}
    			System.out.println("<========clear Content  data Sussess!!==============>content name:"+gcont.getStr(GroupContactsModel.CNAMES));
    			flag=gcont.delete();
    			System.out.println("<========clear Content data Sussess!!========>flag:"+flag);
    		}
    	}
    }
    
    /**
     * 清理团体会员数据
     */
    public void clearGroupMemberData()
    {
    	String groupid=null,tcode=null,mgroupids=null;
    	StringBuffer bumids=new StringBuffer();
    	
    	String[] mids=null;
    	String[] groupids=null;
    	GroupMemberModel gmember=null;
    	GroupMemberinfoModel gmemberinfo=null;
    	Boolean flag=false;
    	groupid=getPara("groupid");
    	tcode=getPara("tcode");
    	if(groupid==null||tcode==null||!tcode.equals("21218cca77804d2ba1922c33e0151105"))
    	{
    		return;
    	}
    	List<GroupMemberModel> listmeb=GroupMemberModel.dao.find("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and groupids='"+groupid+"'");
    	if(listmeb!=null)
    	{
    		mids=new String[listmeb.size()];
    		int i=0;
    		for(GroupMemberModel gememb:listmeb)
    		{
    			mids[i]=gememb.getStr(GroupMemberModel.MID);
    			flag=gememb.delete();
    			System.out.println("<========clear Content member data Sussess!!========>flag:"+flag);
				if(!flag)
				{
					flag=false;
				}
				i++;
    		}
    		System.out.println("<========clear GROUP member data OK!!=========================>");
    		System.out.println("<========clear MIDS:"+mids.toString());
    		System.out.println("<========begin  clear GROUP memberinfo data =========================>");
    		for(String mid:mids)
    		{   			
    			gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
    			flag=gmemberinfo.delete();
    			System.out.println("<========clear Content member data Sussess!!========>flag:"+flag);
				if(!flag)
				{
					flag=false;
				}
    	    }
    		System.out.println("<========clear GROUP memberinfo data OK!!=========================>");
    	}
    	System.out.println("<========you opention OK!!");
    }
    /**
     * 清除去会员详细信息
     */
    public void clearStringMids()
    {
    	//String mids="13808008817,18990461068,13981827625,13608011988,13608183093,15908191111,13980707373,13908029028,15828012222,13880844000,13981072918,13679010058,13980052228,15882458880,18898003777,15726787777,13980530966,15196642222,13008105235,13980726858,13980596290,13308221318,13708189605,13558787166,13908204342,13438452234,13981748483,13540086248,18828059599,13981747148,13808032376,13970412217,13547963333,13882916678,13808170689,13658037088,13980583128,13982218888,13908221214,13518213988,13908182907,13518213788,13308196858,13881868689,15682277777,15388139792,13980521798,13608087767,18600008868,13808015499,13548176711,13808049198,13980300235,13808280719,18602836179,13980302991,13908089703,13980188943,13706131773,13198597717,18990111222,15892784418,13088069562,13348841771,13980018588,15828347888,13980623817,15170287777,13880880837,13684007777,15608191188,13558695590,18657772033,18628394486,18628118911,15881188039,13330997123,13908057522,13880905166,18081036621,13708163176,13909070842,13808054131,13308093608,18481278666,13907946681,13990645978,13980932110,13258328879,13508080202,13807068752,13980839645,13981811699,18048572116,18628097928,15202887229,13980091639,13558752099,18607919591,13540681262,15828388873,15902860988,13808095597,13398181372,13678148364,13880778788,13438099393,13980883258,13699095678,13882281312,13882072025,13708172544,15882259520,13880919689,13908085609,13980663585,13540427647,13980557831,13880557360,18608019640,13408539766,13550207672,15802836609,13688153118,18628161355,18613209205,13730613668,15828012158,18628972303,18628198078,15008201198,13688176689,13307051302,13408552123,13540667125,13880209060,15982462278,15328688199,15983521550,13908189961,13806903709,13308196897,13340987881,13540733448,13666231877,13036691901,18980725619,13730801781,15198268886,18980811136,18384107395,13880631856,13808129479,18728485556,13576907751,15882325457,18608341020,15818315898,13808087713,18200503968,13882090399,13980958906,13708266982,13908131428,13880732699,13882507743,18227627188,13981924689,13981820638,13980958609,18602895099,13880889370,15802899622,13072885785,18683680101,18982190718,18908188813,13551090113,13880669965,18702893279,15708471728,13439960393,15928031573,15902878288,18628318866,13438882999,13982036363,15390243399,18200583968,18780319191,15908110860,13438968223,18280221597,13258388767,13693452867,15170130092,13699591999,18602879295,18583299185,15107910501,13980974558,13908020699,13881783009,18780098721,18781911800";
    	String mids=getPara("mids");
    	if(mids!=null)
    	{
    	
	    	String[] midss=mids.split(",");
	    	GroupMemberinfoModel gmemberinfo=null;
	    	Boolean flag=false;
	    	int i=1;
	    	for(String mid:midss)
			{
				gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
				if(gmemberinfo!=null)
				{
					flag=gmemberinfo.delete();
					System.out.println("第"+i+"个数据<========clear Content memberinfo data Sussess!!========>flag:"+mid);
					if(!flag)
					{
						flag=false;
					}
				}else
				{
					System.out.println("第"+i+"个数据<========clear data not find mid false!!========>mid:"+mid);
				}
				i++;
				
		    }
    	}else
    		return;
    }
    
    public void querydatabymid()
    {
    	String groupid=getPara("groupid");//团体ID
    	String mid=getPara("mid");//手机号码 可以多个以逗号
    	String msg="你输入的参数不正确，请重新输入!";
    	String[] temp=null;
    	String[] midsstring=null;
    	GroupMemberModel gmember=null;
    	GroupMemberinfoModel gmemberinfo=null;
    	if(groupid!=null&&mid!=null)
    	{
    		msg="";
    		List<GroupContactsModel> listcont=GroupContactsModel.dao.find("select * from y_group_contacts where 1=1 and  groupid='"+groupid+"'  ORDER BY orderids");
        	if(listcont!=null)
        	{
        		msg="团体职位信息长度："+listcont.size();

        		for(int i=0;i<listcont.size();i++)
        		{
        			
        			if(listcont.get(i).getStr(GroupContactsModel.MIDS).indexOf(",")!=-1)
        			{
        				midsstring=listcont.get(i).getStr(GroupContactsModel.MIDS).split(",");
        				for(int j=0;j<midsstring.length;j++)
        				{
        					if(mid.indexOf(",")!=-1)
            	    		{
            	    			temp=mid.split(",");
            	    			for(String tel:temp)
            	    			{
            	    				if(midsstring[j]==tel)
            	    				{
            	    					msg+="查询号码："+tel+"在<"+listcont.get(i).getStr(GroupContactsModel.CNAMES)+">职位里！！";
            	    					gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+tel+"'");
            	    					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+tel+"'");
            	    					
            	    					if(gmember!=null)
            	    					{
            	    						msg+="查询号码："+tel+"在<会员信息表>真实存在！！";
            	    					}
            	    					if(gmemberinfo!=null)
            	    					{
            	    						msg+="查询号码："+tel+"在<会员详细信息表>真实存在！！";
            	    					}
            	    					
            	    				}else
            	    					continue;
            	    			}
            	    		}else
            	    		{
            	    			if(midsstring[j]==mid)
        	    				{
            	    				msg+="查询号码："+mid+"在<"+listcont.get(i).getStr(GroupContactsModel.CNAMES)+">职位里！！";
        	    					gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+mid+"'");
        	    					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
        	    					
        	    					
        	    					if(gmember!=null)
        	    					{
        	    						msg+="查询号码："+mid+"在<会员信息表>真实存在！！";
        	    					}
        	    					if(gmemberinfo!=null)
        	    					{
        	    						msg+="查询号码："+mid+"在<会员详细信息表>真实存在！！";
        	    					}
        	    				}
            	    		}
        				}
        			}else
        			{
        				if(mid.indexOf(",")!=-1)
        	    		{
        	    			temp=mid.split(",");
        	    			for(String tel:temp)
        	    			{
        	    				if(listcont.get(i).getStr(GroupContactsModel.MIDS)==tel)
        	    				{
        	    					msg+="查询号码："+tel+"在<"+listcont.get(i).getStr(GroupContactsModel.CNAMES)+">职位里！！";
        	    					gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+tel+"'");
        	    					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+tel+"'");
        	    					
        	    					if(gmember!=null)
        	    					{
        	    						msg+="查询号码："+tel+"在<会员信息表>真实存在！！";
        	    					}
        	    					if(gmemberinfo!=null)
        	    					{
        	    						msg+="查询号码："+tel+"在<会员详细信息表>真实存在！！";
        	    					}
        	    				}else
        	    					continue;
        	    			}
        	    		}else
        	    		{
        	    			if(listcont.get(i).getStr(GroupContactsModel.MIDS)==mid)
    	    				{
    	    					msg+="查询号码："+mid+"在<"+listcont.get(i).getStr(GroupContactsModel.CNAMES)+">职位里！！";
    	    					gmember=GroupMemberModel.dao.findFirst("select ids,groupids,groupname,mids from y_group_member where 1=1  and `status`=0 and mids='"+mid+"'");
    	    					gmemberinfo=GroupMemberinfoModel.dao.findFirst("select ids,mids from y_group_memberinfo where 1=1   and mids='"+mid+"'");
    	    					

    	    					if(gmember!=null)
    	    					{
    	    						msg+="查询号码："+mid+"在<会员信息表>真实存在！！";
    	    					}
    	    					if(gmemberinfo!=null)
    	    					{
    	    						msg+="查询号码："+mid+"在<会员详细信息表>真实存在！！";
    	    					}
    	    				}
        	    		}
        			}	
        		}

        	}else
        	{
        		msg="团体职位信息为空！请检查数据库是否有数据或者你提供的团体ID是否正确！！！";
        	}
    		setAttr("msg", msg);
    	}else
    	{
    		setAttr("msg", msg);
    	}
    	render("api/result.html");
    }
    /**
     * 会员表y_group_member
     * 为所有会员赋值realname、msex、headimage、txlid
     */
    public void updateMember(){
    	//查询所有通讯录的ids、mids----y_group_contacts
    	String sql = "SELECT * FROM y_group_contacts";
    	List<GroupContactsModel> models = GroupContactsModel.dao.find(sql);
    	String[] mids = null;
    	String mid_sql = null;//修改会员基础信息表的sql
    	String info_sql = null;//修改会员详细信息表的sql
    	GroupMemberinfoModel memberinfo = null;
    	String memberid = null;//会员基础信息主键
    	for (GroupContactsModel contactsl : models) {
    		//通过通讯录的mids查询所有相关的会员基础信息数据----y_group_member
    		if(contactsl.getStr("mids") != null){//判断mids是否为null
	    		mids = (contactsl.getStr("mids")).split(",");
	    		for (String mid : mids) {
	    			//通过mids查询会员基础表主键
	    			memberid = Db.queryStr("SELECT ids FROM y_group_member WHERE mids = '"+mid+"'");
	    			//通过通讯录的mids查询所有相关的会员详细信息数据----y_group_memberinfo
	    			memberinfo = GroupMemberinfoModel.dao.findFirst("SELECT * FROM y_group_memberinfo WHERE mids = '"+mid+"'");
	    			if(memberinfo != null){//判断mids是否能在详细表查找到
	    				//修改会员基础表的realname、msex、headimage、txlid字段值
	    				System.out.println("realname:"+memberinfo.getStr("realname")+"  msex:"+memberinfo.getStr("msex")+"  txlid:"+contactsl.getStr("ids")+"  headimage:"+memberinfo.getStr("mheadimage")+"  mids:"+mid);
	    				mid_sql = "UPDATE y_group_member SET txlid='"+contactsl.getStr("ids")+"',realname = '"+memberinfo.getStr("realname")+"',msex = '"+memberinfo.getStr("msex")+"',headimage = '"+memberinfo.getStr("mheadimage")+"' WHERE mids = '"+mid+"'";
	    				Db.update(mid_sql);
	    				//修改会员详细信息表的memberid字段值
	    				info_sql = "UPDATE y_group_memberinfo SET memberid='"+memberid+"' WHERE mids = '"+mid+"'" ;
	    				Db.update(info_sql);
	    			}
				}
    		}
    	}
    }
}
